package com.zy.ivideo.controller;

import com.zy.ivideo.entity.CollectionEntity;
import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.service.CollectionService;
import com.zy.ivideo.token.UserToken;
import com.zy.ivideo.utils.MD5Util;
import com.zy.ivideo.utils.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/collection")
@Api(value = "收藏模块API接口", description = "该模块提供收藏模块服务", tags = "收藏模块")
public class CollectionController {
    @Autowired
    CollectionService service;

    /**
     * 收藏
     *
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "收藏", notes = "收藏", httpMethod = "POST")
    @PostMapping("/collection")
    public ResponseEntity<CollectionEntity> collection(@RequestBody
                                                       @ApiParam(value = "收藏实体", name = "entity", required = true)
                                                               CollectionEntity entity) {
        entity.setVerifycode(MD5Util.getMD5(entity.getItemcode()+entity.getSourceflag()+entity.getUserid()));
        return service.collection(entity);
    }


    /**
     * 取消收藏
     *
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "取消收藏", notes = "取消收藏", httpMethod = "DELETE")
    @DeleteMapping("/unCollection")
    public ResponseEntity<Boolean> unCollection(@RequestBody
                                                @ApiParam(value = "收藏实体", name = "entity", required = true)
                                                        CollectionEntity entity) {
        return service.unCollection(entity);
    }
}
